<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<title>Marketing Kit - Mobile</title>
		<link rel="stylesheet" href="css/themes/Bootstrap.css">
		<link rel="stylesheet" href="css/jquery.mobile.structure-1.4.0.min.css" />
		<link rel="stylesheet" href="css/jquery.mobile.icons.min.css" />
		<script src="js/jquery-1.8.2.min.js"></script>
		<script src="js/jquery.mobile-1.4.0.min.js"></script>
		<script type="text/javascript" src="cordova.js"></script>
		<script>
			//global variable
			var version = localStorage.getItem('ls_lastversion');
			var compName = localStorage.getItem('ls_compname');
			var updateStatus = localStorage.getItem('ls_update');
			var compId = localStorage.getItem('ls_compid');
			
			var db = null;	
			
			//database connection
			init();
			
			$(document).ready(function(){
															
				$('#lableTitle').text(compName);						
				$('#labelGroup').text(getParam('cat_name'));		
				
				$("#btnBack").click(function(){
					$.mobile.loading( 'show', {
						text: 'Loading to back!',
						textVisible: true,
						theme: 'c',
						html: ""
					});
					
        			parent.history.back();
				});
								
			});
						
			function getParam( name ){
				name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
				var regexS = "[\\?&]"+name+"=([^&#]*)";  
				var regex = new RegExp( regexS );  
				var results = regex.exec( window.location.href ); 
				if( results == null )
					return "";  
				else
					return results[1];
			}
			
			function onDeviceReady(){
				try{
					db = window.openDatabase("marketkit", "1.0", "Market Kit Database", 1000000);
														
					db.transaction(
						function(tx){
							var newsId=getParam('news_id');															
							var sql = 'select * from tb_news where news_id='+newsId;	
							//alert('sql:'+sql);													
							tx.executeSql(sql, [], function (tx, result){
								var index = 0;
								for(var i=0;i<result.rows.length;i++){
									var obj = result.rows.item(i);
									$('#txtTitle').text(obj.title);	
									$('#txtDate').text(obj.newsdate);	
									$('#txtContent').html(obj.description);								
									index++;
								}	
								
								if(index==0){
									$('#txtContent').append('<strong style="color:red">Tidak ada data.</strong>');
								}
																			
							});
						}, function(err){
						
						}, function(){
							//alert('query get version ok');
						}
					);
											
				}catch(e){
					alert("error:"+e);
				}
			}
			
			function init(){
	   			document.addEventListener("deviceready",onDeviceReady, false);
	   		}
	   		
		</script>
	</head>
	<body>
		<div data-role="page" data-theme="c">
			<div data-role="header" data-position="fixed">
				<a href="#" id="btnBack" name="btnBack" data-icon="arrow-l" data-theme="c">Back</a>	
				<h1 id="lableTitle">Marketing Kit - Mobile</h1>
			</div>
			<div id="contentId" data-role="content" data-theme="a">
				<h3 style="color:red" id="labelGroup"></h3>
				<strong id="txtTitle" style="color:red"></strong><br/>
				<small><i id="txtDate" style="color:grey"></i></small>
				<p id="txtContent"></p>								
			</div>
		</div>
	</body>
</html>